home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / dos / close.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  145 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: close.c,v 1.4 1996/08/13 13:52:45 digulla Exp $
  4.     $Log: close.c,v $
  5.     Revision 1.4  1996/08/13 13:52:45  digulla
  6.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  7.     Replaced __AROS_LA by __AROS_LHA
  8.  
  9.     Revision 1.3  1996/08/12 14:17:34  digulla
  10.     Added alias UnLock Close
  11.  
  12.     Revision 1.2  1996/08/01 17:40:48  digulla
  13.     Added standard header for all files
  14.  
  15.     Desc:
  16.     Lang: english
  17. */
  18. #include <clib/exec_protos.h>
  19. #include <dos/dosextens.h>
  20. #include <dos/filesystem.h>
  21. #include <clib/dos_protos.h>
  22. #include "dos_intern.h"
  23.  
  24. /*****************************************************************************
  25.  
  26.     NAME */
  27.     #include <clib/dos_protos.h>
  28.  
  29.     __AROS_LH1(BOOL, Close,
  30.  
  31. /*  SYNOPSIS */
  32.     __AROS_LHA(BPTR, file, D1),
  33.  
  34. /*  LOCATION */
  35.     struct DosLibrary *, DOSBase, 6, Dos)
  36.  
  37. /*  FUNCTION
  38.     Close a filehandle opened with Open(). If the file was used
  39.     with buffered I/O the final write may fail and thus Close()
  40.     return an error. The file is closed in any case.
  41.  
  42.     INPUTS
  43.     file   - filehandle
  44.  
  45.     RESULT
  46.     0 if there was an error. !=0 on success.
  47.  
  48.     NOTES
  49.     This function is identical to Lock().
  50.  
  51.     EXAMPLE
  52.  
  53.     BUGS
  54.  
  55.     SEE ALSO
  56.  
  57.     INTERNALS
  58.  
  59.     HISTORY
  60.     29-10-95    digulla automatically created from
  61.                 dos_lib.fd and clib/dos_protos.h
  62.  
  63. *****************************************************************************/
  64.  
  65. /*****************************************************************************
  66.  
  67.     NAME
  68.     #include <clib/dos_protos.h>
  69.  
  70.     __AROS_LH1(BOOL, UnLock,
  71.  
  72.     SYNOPSIS
  73.     __AROS_LHA(BPTR, lock, D1),
  74.  
  75.     LOCATION
  76.     struct DosLibrary *, DOSBase, 15, Dos)
  77.  
  78.     FUNCTION
  79.     Free a lock created with Lock().
  80.  
  81.     INPUTS
  82.     lock - The lock to free
  83.  
  84.     RESULT
  85.  
  86.     NOTES
  87.     This function is identical to Close() - see there.
  88.  
  89.     EXAMPLE
  90.  
  91.     BUGS
  92.  
  93.     SEE ALSO
  94.  
  95.     INTERNALS
  96.  
  97.     HISTORY
  98.     29-10-95    digulla automatically created from
  99.                 dos_lib.fd and clib/dos_protos.h
  100.  
  101. *****************************************************************************/
  102. /*AROS alias UnLock Close */
  103. {
  104.     __AROS_FUNC_INIT
  105.     __AROS_BASE_EXT_DECL(struct DosLibrary *,DOSBase)
  106.  
  107.     /* Get pointer to filehandle */
  108.     struct FileHandle *fh=(struct FileHandle *)BADDR(file);
  109.  
  110.     /* Get pointer to process structure */
  111.     struct Process *me=(struct Process *)FindTask(NULL);
  112.  
  113.     /* Get pointer to I/O request. Use stackspace for now. */
  114.     struct IOFileSys io,*iofs=&io;
  115.  
  116.     /* The returncode defaults to OK. */
  117.     BOOL ret=1;
  118.  
  119.     /* 0 handles are OK */
  120.     if(!file)
  121.     return ret;
  122.  
  123.     /* If the filehandle has a pending write on it Flush() the buffer. */
  124.     if(fh->fh_Flags&FHF_WRITE)
  125.     ret=Flush(file);
  126.  
  127.     /* Prepare I/O request. */
  128.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  129.     iofs->IOFS.io_Message.mn_ReplyPort     =&me->pr_MsgPort;
  130.     iofs->IOFS.io_Message.mn_Length     =sizeof(struct IOFileSys);
  131.     iofs->IOFS.io_Device =fh->fh_Device;
  132.     iofs->IOFS.io_Unit     =fh->fh_Unit;
  133.     iofs->IOFS.io_Command=FSA_CLOSE;
  134.     iofs->IOFS.io_Flags  =0;
  135.  
  136.     /* Send the request. No errors possible. */
  137.     (void)DoIO(&iofs->IOFS);
  138.  
  139.     FreeDosObject(DOS_FILEHANDLE,fh);
  140.  
  141.     /* All done. */
  142.     return ret;
  143.     __AROS_FUNC_EXIT
  144. } /* Close */
  145.